package com.wntms.zjy.web;

import com.github.pagehelper.PageInfo;
import com.wntms.zjy.pojo.CustomerComplain;
import com.wntms.zjy.pojo.Result;
import com.wntms.zjy.service.CustomerComplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xzbz
 * @create 2022-11-23 11:55
 */
@RestController
@RequestMapping("/complain")
public class CustomerComplainController {

    @Autowired
    CustomerComplainService customerComplainService;
    @DeleteMapping("/{id}")
    public Result deleteComplain(@PathVariable Integer id){
        boolean flag = customerComplainService.deleteComplain(id);
        if(!flag){
            return Result.error("");
        }else{
            return Result.success(id,"执行成功");
        }
    }
    @PostMapping()
    public Result addComplain(@RequestBody CustomerComplain customerComplain){
        boolean flag = customerComplainService.addComplain(customerComplain);
        if(!flag){
            return Result.error("");
        }else{
            return Result.success(null,"执行成功");
        }
    }
    //回复投诉内容

    @PutMapping
    public Result replyComplain(@RequestBody CustomerComplain customerComplain){
        boolean flag = customerComplainService.replyComplain(customerComplain);
        if(!flag){
            return Result.error("");
        }else{
            return Result.success(null,"执行成功");
        }
    }
    @GetMapping
    public Result findAll(){
        List<CustomerComplain> customerComplains = customerComplainService.findAll();
        if(customerComplains == null){
            return Result.error("");
        }else{
            return Result.success(customerComplains,"执行成功");
        }
    }

    @PostMapping("/{fid}")
    public Result findByFid(@PathVariable String fid){
        CustomerComplain customerComplain = customerComplainService.findByFid(fid);
        if(customerComplain == null){
            return Result.error("");
        }else{
            return Result.success(customerComplain,"执行成功");
        }

    }

    @GetMapping("/{currentPage}/{pageSize}")
    public Result findByPage(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        List<CustomerComplain> customerComplains = customerComplainService.findByPage(currentPage, pageSize);
        PageInfo<CustomerComplain> pageInfo = new PageInfo<>(customerComplains);
        if(pageInfo == null){
            return Result.error("");
        }else {
            return Result.success(pageInfo,"执行成功");
        }
    }
}
